package org.ala.tcp_feign_common.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 关闭原因枚举
 * 
 * @author 骆毅(ala)
 * @date 2024年4月19日
 */
public enum TcpFeignCloseTypeEnums {

	LOGIN_ERROR((byte)1, "登录错误"),
	LOGIN_TIMEOUT((byte)2, "登录超时"),
	
	MAX_CONNECTION((byte)3, "连接数超限"),
	HEART_ERROR((byte)4, "心跳未及时回复")
	;
	private byte val;
	private String desc;
	private TcpFeignCloseTypeEnums(byte val, String desc) {
		this.val = val;
		this.desc = desc;
	}
	
	
	static Map<Byte, TcpFeignCloseTypeEnums> valMapper;
	public static TcpFeignCloseTypeEnums val(byte val) {
		if (valMapper == null) {
			synchronized (TcpFeignCloseTypeEnums.class) {
				if (valMapper == null) {
					valMapper = Arrays.stream(values()).collect(Collectors.toMap(c->c.getVal(), c->c));
				}
			}
		}
		return valMapper.get(val);
	}
	
	
	public byte getVal() {
		return val;
	}
	public void setVal(byte val) {
		this.val = val;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
}
